package br.edu.universo.si.projeto2.infojob.server.negocio;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;

import br.edu.universo.si.projeto2.infojob.client.bean.BeanEmpresaAssinante;
import br.edu.universo.si.projeto2.infojob.client.bean.BeanProfissionalAssinante;
import br.edu.universo.si.projeto2.infojob.client.bean.BeanProfissionalCurriculo;
import br.edu.universo.si.projeto2.infojob.client.bean.BeanVaga;
import br.edu.universo.si.projeto2.infojob.server.excecoes.CurriculoEnviadoException;
import br.edu.universo.si.projeto2.infojob.server.persistencia.PCurriculo;
import br.edu.universo.si.projeto2.infojob.server.persistencia.PVagas;

public class NVagas
{
	public static void cadastrarVaga(BeanVaga vaga) throws Exception
	{
		try
		{
			PVagas.cadastrarVaga(vaga);
		}
		catch (SQLException ex)
		{
			ex.printStackTrace();
		  	throw new Exception(ex.toString());
		}
		catch (ClassNotFoundException ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.toString());
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.toString());			
		}
	}
	
	public static ArrayList<BeanVaga> buscarVagas(BeanVaga filtro) throws Exception
	{
		try
		{
			  return PVagas.buscarVagas(filtro);
		}
		catch (ClassNotFoundException ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.toString());
		}
		catch (SQLException ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.toString());
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.toString());
		}
	}
	
	public static ArrayList<BeanProfissionalAssinante> getProfissionaisByVaga(int vagaId) throws Exception
	{
		try
		{
			  return PVagas.getProfissionaisByVaga(vagaId);
		}
		catch (ClassNotFoundException ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.toString());
		}
		catch (SQLException ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.toString());
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.toString());
		}
	}
	
	public static BeanVaga getVagaById(Integer idVaga) throws Exception
	{
		try
		{
			return PVagas.getVagaById(idVaga);
		}
		catch (ClassNotFoundException ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.toString());
		}
		catch (SQLException ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.toString());
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.toString());			  
		}
	}

	public static void excluirEnvioDeCurriculo(Connection conn, BeanProfissionalCurriculo curriculo) throws Exception
	{
		PCurriculo.excluirEnvioDeCurriculo(conn, curriculo);
	}

	public static void inserirCandidato(BeanVaga vaga, BeanProfissionalCurriculo curriculo) throws Exception
	{
		try
		{
			if (PVagas.verificarEnvioCurriculo(vaga, curriculo))
			{
				throw new CurriculoEnviadoException();
			}
			
			PVagas.inserirCandidato(vaga, curriculo);
		}
		catch (ClassNotFoundException ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.toString());
		}
		catch (SQLException ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.toString());
		}
		catch (CurriculoEnviadoException ex)
		{
			ex.printStackTrace();
			throw new Exception(ex.getMessage());
		}
	}
	
	public static void encerrarVaga(BeanVaga bVaga) throws Exception {

			try {
			  PVagas.encerrarVaga(bVaga);
			} catch (ClassNotFoundException ex) {
			  ex.printStackTrace();
			  throw new Exception(ex.toString());
			} catch (SQLException ex) {
			  ex.printStackTrace();
			  throw new Exception(ex.toString());
			} catch (Exception ex) {
			  ex.printStackTrace();
			  throw new Exception(ex.toString());
			}
		  }
	  
	public static void excluirVaga(int idVaga) throws Exception {

			try {
				PVagas.excluirVaga(idVaga);
			} catch (ClassNotFoundException ex) {
			  ex.printStackTrace();
			  throw new Exception(ex.toString());
			} catch (SQLException ex) {
			  ex.printStackTrace();
			  throw new Exception(ex.toString());
			} catch (Exception ex) {
			  ex.printStackTrace();
			  throw new Exception(ex.toString());
			}
		  }
	
	public static ArrayList<BeanVaga> getTodasVagasDaEmpresa(Connection conn, BeanEmpresaAssinante bEmpresaAssinante)
		throws Exception
	{
		return PVagas.getTodasVagasDaEmpresa(conn, bEmpresaAssinante);
	}
}